home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / xlib05.zip / XCOMPPBM.ASM < prev    next >
Assembly Source File  |  1993-08-25  |  8KB  |  323 lines

  1. ;-----------------------------------------------------------------------
  2. ; module XCOMPPBM
  3. ;
  4. ; This module contains only the compiler and sizeof routines --
  5. ; use the plotter from XCBITMAP.
  6. ;
  7. ;-----------------------------------------------------------------------
  8.  
  9. include xlib.inc
  10. include xcomppbm.inc
  11.  
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13. ; _x_compile_pbm
  14. ;
  15. ; I only changed five instructions, instead of rewriting this
  16. ; for PBMs.  So it is amazingly inefficient.  But, what the hell,
  17. ; It's only a game :).
  18. ;
  19.  
  20. ; accessory macros to save typing (what else?)
  21. Emitb macro arg
  22.     mov byte ptr es:[di],&arg&
  23.     inc di
  24.     endm
  25.  
  26. Emitw macro arg
  27.     mov word ptr es:[di],&arg&
  28.     add di,2
  29.     endm
  30.  
  31. ; opcodes emitted by _x_compile_pbm
  32. ROL_AL          equ 0c0d0h              ; rol al
  33. SHORT_STORE_8   equ 044c6h              ; mov [si]+disp8,  imm8
  34. STORE_8         equ 084c6h              ; mov [si]+disp16, imm8
  35. SHORT_STORE_16  equ 044c7h              ; mov [si]+disp8,  imm16
  36. STORE_16        equ 084c7h              ; mov [si]+disp16, imm16
  37. ADC_SI_IMMED    equ 0d683h              ; adc si,imm8
  38. OUT_AL          equ 0eeh                ; out dx,al
  39. RETURN          equ 0cbh                ; ret
  40.  
  41.  
  42. .data
  43.  
  44. align 2
  45. ColumnMask      db      011h,022h,044h,088h
  46.  
  47.  
  48. .code
  49.  
  50.     align   2
  51. _x_compile_pbm proc
  52. ARG   logical_width:word,bitmap:dword,output:dword
  53. LOCAL bwidth,scanx,scany,outputx,outputy,column,set_column,input_size:word=LocalStk
  54.     push bp
  55.     mov  bp, sp         ; caller's stack frame
  56.     sub  sp,LocalStk    ; local space
  57.     push si
  58.     push di
  59.     push ds
  60.  
  61.     mov word ptr [scanx],0
  62.     mov word ptr [scany],0
  63.     mov word ptr [outputx],0
  64.     mov word ptr [outputy],0
  65.     mov word ptr [column],0
  66.     mov word ptr [set_column],0
  67.  
  68.     lds si,[bitmap]     ; 32-bit pointer to source bitmap
  69.  
  70.     les di,[output]     ; 32-bit pointer to destination stream
  71.  
  72.     lodsb               ; load width byte
  73.     xor ah, ah          ; convert to word
  74.     mov [bwidth], ax    ; save for future reference
  75.     mov bl, al          ; copy width byte to bl
  76.     lodsb               ; load height byte -- already a word since ah=0
  77.     mul bl              ; mult height word by width byte
  78.     mov [input_size], ax;  to get pixel total
  79.  
  80. @@MainLoop:
  81.     mov bx, [scanx]     ; position in original bitmap
  82.     add bx, [scany]
  83.  
  84.     mov al, [si+bx]     ; get pixel
  85.     or  al, al          ; skip empty pixels
  86.     jnz @@NoAdvance
  87.     jmp @@Advance
  88. @@NoAdvance:
  89.  
  90.     mov dx, [set_column]
  91.     cmp dx, [column]
  92.     je @@SameColumn
  93. @@ColumnLoop:
  94.     Emitw ROL_AL        ; emit code to move to new column
  95.     Emitw ADC_SI_IMMED
  96.     Emitb 0
  97.  
  98.     inc dx
  99.     cmp dx, [column]
  100.     jl @@ColumnLoop
  101.  
  102.     Emitb OUT_AL        ; emit code to set VGA mask for new column
  103.     mov [set_column], dx
  104. @@SameColumn:
  105.     mov dx, [outputy]   ; calculate output position
  106.     add dx, [outputx]
  107.     sub dx, 128
  108.  
  109.     inc word ptr [scanx]
  110.     mov cx, [scanx]     ; within four pixels of right edge?
  111.     cmp cx, [bwidth]
  112.     jge @@OnePixel
  113.  
  114.     inc word ptr [outputx]
  115.     mov ah, [si+bx+1]   ; get second pixel
  116.     or ah, ah
  117.     jnz @@TwoPixels
  118. @@OnePixel:
  119.     cmp dx, 127         ; can we use shorter form?
  120.     jg @@OnePixLarge
  121.     cmp dx, -128
  122.     jl @@OnePixLarge
  123.     Emitw SHORT_STORE_8
  124.     Emitb dl            ; 8-bit position in output
  125.     jmp @@EmitOnePixel
  126. @@OnePixLarge:
  127.     Emitw STORE_8
  128.     Emitw dx            ; position in output
  129. @@EmitOnePixel:
  130.     Emitb al
  131.     jmp short @@Advance
  132. @@TwoPixels:
  133.     cmp dx, 127
  134.     jg @@TwoPixLarge
  135.     cmp dx, -128
  136.     jl @@TwoPixLarge
  137.     Emitw SHORT_STORE_16
  138.     Emitb dl            ; 8-bit position in output
  139.     jmp @@EmitTwoPixels
  140. @@TwoPixLarge:
  141.     Emitw STORE_16
  142.     Emitw dx            ; position in output
  143. @@EmitTwoPixels:
  144.     Emitw ax
  145.  
  146. @@Advance:
  147.     inc word ptr [outputx]
  148.     mov ax, [scanx]
  149.     inc ax
  150.     cmp ax, [bwidth]
  151.     jl @@AdvanceDone
  152.     mov dx, [outputy]
  153.     add dx, [logical_width]
  154.     mov cx, [scany]
  155.     add cx, [bwidth]
  156.     cmp cx, [input_size]
  157.     jl @@NoNewColumn
  158.     inc word ptr [column]
  159.     mov cx, [column]
  160.     cmp cx, 4
  161.     je @@Exit           ; Column 4: there is no column 4.
  162.     xor cx, cx          ; scany and outputy are 0 again for
  163.     mov dx, cx          ; the new column
  164.     add si, [input_size]
  165. @@NoNewColumn:
  166.     mov [outputy], dx
  167.     mov [scany], cx
  168.     xor ax, ax
  169.     mov word ptr [outputx], 0
  170. @@AdvanceDone:
  171.     mov [scanx], ax
  172.     jmp @@MainLoop
  173.  
  174. @@Exit:
  175.     Emitb RETURN
  176.     mov ax,di
  177.     sub ax,word ptr [output] ; size of generated code
  178.  
  179.     pop ds
  180.     pop di
  181.     pop si
  182.     mov sp, bp
  183.     pop bp
  184.  
  185.     ret
  186. _x_compile_pbm endp
  187.  
  188.  
  189. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  190. ; _x_sizeof_cpbm
  191. ;
  192.  
  193.  
  194.     align   2
  195. _x_sizeof_cpbm proc
  196. ARG   logical_width:word,bitmap:dword
  197. LOCAL bwidth,scanx,scany,outputx,outputy,column,set_column,input_size:word=LocalStk
  198.     push bp
  199.     mov  bp, sp         ; caller's stack frame
  200.     sub  sp,LocalStk    ; local space
  201.     push si
  202.     push di
  203.     push ds
  204.  
  205.     mov word ptr [scanx], 0
  206.     mov word ptr [scany], 0
  207.     mov word ptr [outputx], 0
  208.     mov word ptr [outputy], 0
  209.     mov word ptr [column], 0
  210.     mov word ptr [set_column], 0
  211.  
  212.     lds si,[bitmap]     ; 32-bit pointer to source bitmap
  213.  
  214.     mov di, 1           ; initial size is just the size of the far RET
  215.  
  216.     lodsb               ; load width byte
  217.     xor ah, ah          ; convert to word
  218.     mov [bwidth], ax    ; save for future reference
  219.     mov bl, al          ; copy width byte to bl
  220.     lodsb               ; load height byte -- already a word since ah=0
  221.     mul bl              ; mult height word by width byte
  222.     mov [input_size], ax;  to get pixel total
  223.  
  224. @@MainLoop:
  225.     mov bx, [scanx]     ; position in original bitmap
  226.     add bx, [scany]
  227.  
  228.     mov al, [si+bx]     ; get pixel
  229.     or  al, al          ; skip empty pixels
  230.     jnz @@NoAdvance
  231.     jmp @@Advance
  232. @@NoAdvance:
  233.  
  234.     mov dx, [set_column]
  235.     cmp dx, [column]
  236.     je @@SameColumn
  237. @@ColumnLoop:
  238.     add di, 5           ; size of code to move to new column
  239.     inc dx
  240.     cmp dx,[column]
  241.     jl @@ColumnLoop
  242.  
  243.     inc di              ; size of code to set VGA mask
  244.     mov [set_column], dx
  245. @@SameColumn:
  246.     mov dx, [outputy]   ; calculate output position
  247.     add dx, [outputx]
  248.     sub dx, 128
  249.  
  250.     inc word ptr [scanx]
  251.     mov cx, [scanx]     ; within four pixels of right edge?
  252.     cmp cx, [bwidth]
  253.     jge @@OnePixel
  254.  
  255.     inc word ptr [outputx]
  256.     mov ah,[si+bx+1]    ; get second pixel
  257.     or ah, ah
  258.     jnz @@TwoPixels
  259. @@OnePixel:
  260.     cmp dx, 127         ; can we use shorter form?
  261.     jg @@OnePixLarge
  262.     cmp dx, -128
  263.     jl @@OnePixLarge
  264.     add di, 4           ; size of 8-bit position in output plus one pixel
  265.     jmp @@EmitOnePixel
  266. @@OnePixLarge:
  267.     add di, 5           ; size of position in output plus one pixels
  268. @@EmitOnePixel:
  269.     jmp short @@Advance
  270. @@TwoPixels:
  271.     cmp dx, 127
  272.     jg @@TwoPixLarge
  273.     cmp dx, -128
  274.     jl @@TwoPixLarge
  275.     add di, 5           ; size of 8-bit position in output plus two pixels
  276.     jmp @@EmitTwoPixels
  277. @@TwoPixLarge:
  278.     add di, 6           ; size of 16-bit position in output plus two pixels
  279. @@EmitTwoPixels:
  280.  
  281. @@Advance:
  282.     inc word ptr [outputx]
  283.     mov ax, [scanx]
  284.     inc ax
  285.     cmp ax, [bwidth]
  286.     jl @@AdvanceDone
  287.     mov dx, [outputy]
  288.     add dx, [logical_width]
  289.     mov cx, [scany]
  290.     add cx, [bwidth]
  291.     cmp cx, [input_size]
  292.     jl @@NoNewColumn
  293.     inc word ptr [column]
  294.     mov cx, [column]
  295.     cmp cx, 4
  296.     je @@Exit           ; Column 4: there is no column 4.
  297.     xor cx,cx           ; scany and outputy are 0 again for
  298.     mov dx,cx           ; the new column
  299.     add si, [input_size]
  300. @@NoNewColumn:
  301.     mov [outputy], dx
  302.     mov [scany], cx
  303.     xor ax, ax
  304.     mov word ptr [outputx], ax
  305. @@AdvanceDone:
  306.     mov [scanx], ax
  307.     jmp @@MainLoop
  308.  
  309. @@Exit:
  310.     mov ax, di          ; size of generated code
  311.  
  312.     pop ds
  313.     pop di
  314.     pop si
  315.     mov sp,bp
  316.     pop bp
  317.  
  318.     ret
  319. _x_sizeof_cpbm endp
  320.  
  321. end
  322.  
  323.